<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
    <script>
/*
        function fa() {
            var x=document.getElementById("n1");
            var y=document.getElementById("n2");
            var a=parseFloat(x.value);
            var b=parseFloat(y.value);
            this.a;
            this.b;
        }*/
        function adder() {
            var x=document.getElementById("n1");
            /*if (isNaN(x)){
                alert("aaa");
                return
            }*/
            var y=document.getElementById("n2");
           /* if (isNaN(y)){
                alert("bbbb")
                return
            }*/
            a=parseFloat(x.value);
            b=parseFloat(y.value);
            var res=document.getElementById("r2");
            res.value=a+b;
        }
        function suber() {
            var x=document.getElementById("n1");
            var y=document.getElementById("n2");
          /*  if (isNaN(x)){
                alert("aaa")
                return
            }
            if (isNaN(y)){
                alert("bbbb")
                return
            }*/
            a=parseFloat(x.value);
             b=parseFloat(y.value);
            var res=document.getElementById("r2");
            res.value=a-b;

        }
        function ma() {
            var x=document.getElementById("n1");
            var y=document.getElementById("n2");
           /* if (isNaN(x)){
                alert("aaaa")
                return
            }
            if (isNaN(y)){
                alert("bbbb")
                return

            }*/
             a=parseFloat(x.value);
            b=parseFloat(y.value);
            var res=document.getElementById("r2");
            res.value=a*b;

        }
        function chu() {
            var x=document.getElementById("n1");
            var y=document.getElementById("n2");
            a=parseFloat(x.value);
            b=parseFloat(y.value);
            var res=document.getElementById("r2");
            res.value=a/b;

        }
        function clear() {
            document.getElementById('r2').value='';
            document.getElementById('n1').value='';
            document.getElementById('n2').value='';



        }

        function s() {
            document.getElementById('r2').value='';
            document.getElementById('n1').value='';
            document.getElementById('n2').value='';
        }
    </script>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            text-align: center;
        }
        button{
            width: 40px;
            height: 20px;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td>请输入第一个数字</td>
            <td><input type="text"  id="n1"></td>
        </tr>
        <tr>
            <td>请输入第二数字</td>
            <td><input type="text" id="n2" ></td>
        </tr>
        <tr>
            <td>选择您的计算方法
            <button onclick="adder()" value="">+</button>
           <button onclick="suber()" value="">-</button>
           <button onclick="ma()" value="">*</button>
           <button onclick="chu()" value="">/</button>
       <!-- <button onclick="qingchu()" value="">清空</button>-->
                <input type="button" value="清空" onclick="s()" />

            </td>
        </tr>
        <tr>
            <td>您想要的结果是：</td>
            <td><input type="text" id="r2"></td>
        </tr>
    </table>
</body>
</html>